/*
 * Monkey.cpp
 *
 *  Created on: 27/11/2011
 *      Author: joaogf
 */

#include "Monkey.h"

Monkey::Monkey(const int &id):
	id_(id)
{
	img_ = new Image("animal3.png",Point2d(0,0));
	/*Macacos da segunda linha*/
	clips_[0].x = MONKEY_WIDTH * 2;
	clips_[0].y = MONKEY_HEIGHT;
	clips_[0].w = MONKEY_WIDTH;
	clips_[0].h = MONKEY_HEIGHT;
	clips_[1].x = MONKEY_WIDTH;
	clips_[1].y = MONKEY_HEIGHT;
	clips_[1].w = MONKEY_WIDTH;
	clips_[1].h = MONKEY_HEIGHT;
	clips_[2].x = 0;
	clips_[2].y = MONKEY_HEIGHT;
	clips_[2].w = MONKEY_WIDTH;
	clips_[2].h = MONKEY_HEIGHT;
	/*Macacos da terceira linha*/
	clips_[3].x = MONKEY_WIDTH * 2;
	clips_[3].y = MONKEY_HEIGHT * 2;
	clips_[3].w = MONKEY_WIDTH;
	clips_[3].h = MONKEY_HEIGHT;
	clips_[4].x = MONKEY_WIDTH;
	clips_[4].y = MONKEY_HEIGHT * 2;
	clips_[4].w = MONKEY_WIDTH;
	clips_[4].h = MONKEY_HEIGHT;
	clips_[5].x = 0;
	clips_[5].y = MONKEY_HEIGHT * 2;
	clips_[5].w = MONKEY_WIDTH;
	clips_[5].h = MONKEY_HEIGHT;
	img_->setColorKey(ColorsRGB(120,195,128));//Cor de fundo do macaco

	frame_ = 2;
	dir_ = MRIGHT;
}

Monkey::~Monkey()
{
	 /*if(img_)
	 {
		 delete img_;
	 }*/
}

void Monkey::setFrame(const int &frame)
{
	frame_ = frame;
}

const int& Monkey::getFrame()const
{
	return frame_;
}

void Monkey::setDir(const int &dir)
{
	dir_ = dir;
}

const int& Monkey::getDir()const
{
	return dir_;
}


void Monkey::show(SDL_Surface *parent)
{
	Point2d pos = img_->getPos();
	SDL_Rect offset;
	offset.x = pos.x_;
	offset.y = pos.y_;
	SDL_BlitSurface(img_->getImg(),&clips_[frame_],parent,&offset);
	string texto;
	sprintf((char*)texto.c_str(), "%d",id_);
	Text text(texto,"myFont.ttf", 255, 255, 255,15);
	offset.y -= 50;
	SDL_BlitSurface(text.getTextScreen(), NULL, parent, &offset);

}

void Monkey::move(const Point2d &pos)
{
	img_->setPos(pos);
	frame_++;
	if (dir_ == MRIGHT)
	{
		if (frame_ > 2)
		{
			frame_ = 0;
		}
	}
	else
	{
		if (frame_ > 5)
		{
			frame_ = 3;
		}
	}
}


const Point2d& Monkey::getPos()const
{
	return img_->getPos();
}
void Monkey::setStatus(const int &st)
{
	status_ = st;
}
const int& Monkey::getStatus()
{
	return status_;
}

const int & Monkey::getId()
{
	return id_;
}

void Monkey::operator=(const Monkey &mon)
{
	cout<<"copia\n";
	img_ = new Image("animal3.png",mon.getPos());
	/*Macacos da segunda linha*/
	clips_[0].x = MONKEY_WIDTH * 2;
	clips_[0].y = MONKEY_HEIGHT;
	clips_[0].w = MONKEY_WIDTH;
	clips_[0].h = MONKEY_HEIGHT;
	clips_[1].x = MONKEY_WIDTH;
	clips_[1].y = MONKEY_HEIGHT;
	clips_[1].w = MONKEY_WIDTH;
	clips_[1].h = MONKEY_HEIGHT;
	clips_[2].x = 0;
	clips_[2].y = MONKEY_HEIGHT;
	clips_[2].w = MONKEY_WIDTH;
	clips_[2].h = MONKEY_HEIGHT;
	/*Macacos da terceira linha*/
	clips_[3].x = MONKEY_WIDTH * 2;
	clips_[3].y = MONKEY_HEIGHT * 2;
	clips_[3].w = MONKEY_WIDTH;
	clips_[3].h = MONKEY_HEIGHT;
	clips_[4].x = MONKEY_WIDTH;
	clips_[4].y = MONKEY_HEIGHT * 2;
	clips_[4].w = MONKEY_WIDTH;
	clips_[4].h = MONKEY_HEIGHT;
	clips_[5].x = 0;
	clips_[5].y = MONKEY_HEIGHT * 2;
	clips_[5].w = MONKEY_WIDTH;
	clips_[5].h = MONKEY_HEIGHT;
	img_->setColorKey(ColorsRGB(120,195,128));//Cor de fundo do macaco
	frame_ = mon.getFrame();
	dir_ = mon.getDir();
}
